#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

class Node{
public:
    Node(int value){
        this->value = value;
    }
public:
    int value;
    Node* next[2] = {NULL};
    // int end = 0;
    // int tra = 0;
};


class PreTree{
public:
    int add(int value){
        //一边添加，一遍检索
        Node* addhead = head;
        Node* curr = head;
        int maxvalue = 0;
        for(int i = 31;i>=0;--i){
            int T = value>>i;
            if(((T)&1)>0){
                if(addhead->next[1]==NULL)
                    addhead->next[1] = new Node(1);
                addhead = addhead->next[1];
                if(curr->next[0]!=NULL){
                    maxvalue += pow(2,i);
                    curr = curr->next[0];
                }
                else{
                    curr = curr->next[1];
                }
            }
            else{
                if(addhead->next[0]==NULL)
                    addhead->next[0] = new Node(0);
                addhead = addhead->next[0];
                if(curr->next[1]!=NULL){
                    maxvalue += pow(2,i);
                    curr = curr->next[1];
                }
                else {
                    curr = curr->next[0];
                }  
            }
        }
        return maxvalue;
    }
public:
    Node* head = new Node(-1);
};

class Solution {
public:
    int findMaximumXOR(vector<int>& nums) {
        int maxvalue = 0;
        PreTree* pretree = new PreTree();
        for(int i = 0;i<nums.size();++i){
            int temp = pretree->add(nums[i]);
            maxvalue = max(maxvalue,temp);
        }
        return maxvalue;

    }
};





int main(){
    Solution S;
    vector<int> nums = {3,10,5,25,2,8};
    cout<<S.findMaximumXOR(nums)<<endl;
    
}


